package com.remac.framework.mybatisplus.extensions.config;

import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
import com.remac.framework.mybatisplus.extensions.context.MybatisPlusExtensionsContext;
import com.remac.framework.mybatisplus.extensions.enhance.support.GenericTypeHandlerMybatisPlusEnhancer;
import com.remac.framework.mybatisplus.extensions.enhance.support.JsonUnknownTypeHandlerMybatisPlusEnhancer;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Ye Junhui
 * @since 2024/4/24
 */
@Configuration
@AutoConfigureBefore(MybatisPlusAutoConfiguration.class)
public class MybatisPlusExtensionsPreLoadAutoConfiguration {

    @Bean
    public MybatisPlusExtensionsContext mybatisPlusExtensionsContext(){
        return new MybatisPlusExtensionsContext();
    }

    @Bean
    @ConditionalOnMissingBean
    public GenericTypeHandlerMybatisPlusEnhancer genericTypeHandlerMybatisPlusEnhancer(){
        return new GenericTypeHandlerMybatisPlusEnhancer();
    }

    @Bean
    @ConditionalOnMissingBean
    public JsonUnknownTypeHandlerMybatisPlusEnhancer jsonUnknownTypeHandlerMybatisPlusEnhancer(){
        return new JsonUnknownTypeHandlerMybatisPlusEnhancer();
    }
}
